package com.sunwayhorizo.health.hl7.persistent;

import com.sunwayhorizo.health.hl7.datatypes.common.CSImpl;
import com.sunwayhorizo.health.hl7.persistent.pk.RimCoreRoleTelAddrsPK;

import java.io.Serializable;

import java.sql.Timestamp;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;


@Entity
@TableGenerator(name="RoleTelAddrs_IdGenerator", table="RIM_Id_Generator", pkColumnName = "pkColumn", valueColumnName = "valueColumn",pkColumnValue="Role_TelAddrs")
//@NamedQuery(name = "RimCoreRoleTelAddrs.findAll",   query = "select o from RimCoreRoleTelAddrs o")
@Table(name = "RIM_CORE_ROLE_TEL_ADDRS")
@IdClass(RimCoreRoleTelAddrsPK.class)
public class RimCoreRoleTelAddrs implements Serializable {
    @Id
    @Column(name="ROLE_ID", nullable = false, insertable = false,  updatable = false)    private Long roleId;
    @Id
    @Column(name="ROLE_VERSION_NUM", nullable = false, insertable = false,  updatable = false)    private Long roleVersionNum;
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE,generator = "RoleTelAddrs_IdGenerator" )
    @Column(name="TEL_ADDRESS_ID", nullable = false)    private Long telAddressId;
    
    @Column(name="ADDRESS_TXT")    private String address;
    @Column(name="CONTACT_POINT_ID")    private Long contactPointId;
    @Column(name="EFFECTIVE_END_DATE_TS")    private Timestamp effectiveEndDateTs;
    @Column(name="EFFECTIVE_GTS_TXT")    private String effectiveGtsTxt;
    @Column(name="EFFECTIVE_START_DATE_TS")    private Timestamp effectiveStartDateTs;
    @Column(name="URL_SCHEME_CODE", nullable = false)    private String scheme;
    
    @OneToMany(mappedBy = "rimCoreRoleTelAddrs")    private List<RimCoreRoleTelUses> rimCoreRoleTelUsesList = new ArrayList();
    
    @ManyToOne
    @JoinColumns({
    @JoinColumn(name = "ROLE_ID", referencedColumnName = "ROLE_ID"),
    @JoinColumn(name = "ROLE_VERSION_NUM", referencedColumnName = "ROLE_VERSION_NUM")
    })
    private RimCoreRoles rimCoreRoles;

    public RimCoreRoleTelAddrs() {
    }

    public Long getContactPointId() {
        return contactPointId;
    }

    public void setContactPointId(Long contactPointId) {
        this.contactPointId = contactPointId;
    }

    public Timestamp getEffectiveEndDateTs() {
        return effectiveEndDateTs;
    }

    public void setEffectiveEndDateTs(Timestamp effectiveEndDateTs) {
        this.effectiveEndDateTs = effectiveEndDateTs;
    }

    public String getEffectiveGtsTxt() {
        return effectiveGtsTxt;
    }

    public void setEffectiveGtsTxt(String effectiveGtsTxt) {
        this.effectiveGtsTxt = effectiveGtsTxt;
    }

    public Timestamp getEffectiveStartDateTs() {
        return effectiveStartDateTs;
    }

    public void setEffectiveStartDateTs(Timestamp effectiveStartDateTs) {
        this.effectiveStartDateTs = effectiveStartDateTs;
    }

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    public Long getRoleVersionNum() {
        return roleVersionNum;
    }

    public void setRoleVersionNum(Long roleVersionNum) {
        this.roleVersionNum = roleVersionNum;
    }

    public Long getTelAddressId() {
        return telAddressId;
    }

    public void setTelAddressId(Long telAddressId) {
        this.telAddressId = telAddressId;
    }

    public List<RimCoreRoleTelUses> getRimCoreRoleTelUsesList() {
        return rimCoreRoleTelUsesList;
    }

    public void setRimCoreRoleTelUsesList(List<RimCoreRoleTelUses> rimCoreRoleTelUsesList) {
        this.rimCoreRoleTelUsesList = rimCoreRoleTelUsesList;
    }

    private RimCoreRoleTelUses addRimCoreRoleTelUses(RimCoreRoleTelUses rimCoreRoleTelUses) {
        getRimCoreRoleTelUsesList().add(rimCoreRoleTelUses);
        rimCoreRoleTelUses.setRimCoreRoleTelAddrs(this);
        return rimCoreRoleTelUses;
    }

    private RimCoreRoleTelUses removeRimCoreRoleTelUses(RimCoreRoleTelUses rimCoreRoleTelUses) {
        getRimCoreRoleTelUsesList().remove(rimCoreRoleTelUses);
        rimCoreRoleTelUses.setRimCoreRoleTelAddrs(null);
        return rimCoreRoleTelUses;
    }
    
    public void setRoleTelAddrUses(Set mSet){
        CSImpl use = (CSImpl)mSet.iterator().next();
        RimCoreRoleTelUses roleAddrTelUses = new RimCoreRoleTelUses();
        roleAddrTelUses.setUseCode(use.code().toString());
        this.addRimCoreRoleTelUses(roleAddrTelUses);            
    }


    public void setRimCoreRoles(RimCoreRoles rimCoreRoles) {
        this.rimCoreRoles = rimCoreRoles;
    }

    public RimCoreRoles getRimCoreRoles() {
        return rimCoreRoles;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getAddress() {
        return address;
    }

    public void setScheme(String scheme) {
        this.scheme = scheme;
    }

    public String getScheme() {
        return scheme;
    }
}
